layui.use(['jquery', 'table', 'form', 'layer'], function () {
    var $ = layui.jquery;
    var table = layui.table;
    var form = layui.form;
    var layer = layui.layer;
    //使用人id
    var createId = localStorage.getItem('createId');
    $('input[name=implementId]').val(createId);
    //获取审核的id
    var id = $('input[name=id]').val();
    //确定
    form.on('submit(sub)', function (data) {
        $.ajax({
            url: '/record/updateRecordResult',
            type: 'post',
            data: data.field,
            dataType: 'json',
            async:false,
            success: function (item) {
                if (data.field.result == 1){
                    data.field.result = 2;
                }else {
                    data.field.result = 1;
                }
                var auditLog = {
                    'tableName': 'js_course',
                    'type': data.field.result,
                    'userId': createId,
                    'remark': '审核课程',
                    'aduitLogType': 2,
                    'mainId': data.field.id
                }
                addAuditLog(auditLog);
            }
        });
    })

    //添加审核日志
    function addAuditLog(auditLog) {
        $.ajax({
            url: '/aduitLog/addAuditLog',
            type: 'post',
            data: auditLog,
            async:false,
            dataType: 'json',
            success: function (data) {
                close();
                parent.location.reload();
            }
        });
    }

    //取消
    $('#close').on('click', function () {
        close();
    })

    function close() {
        var layer = parent.layer;
        layer.close(layer.index);
    }
})
